package com.bstek.uflo.form.view.common;

import org.htmlparser.nodes.TagNode;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.util.StringUtils;


/**
 * @author Jacky.gao
 * @since 2013年11月6日
 */
public abstract class AbstractComponentBuilder implements ComponentBuilder,ApplicationContextAware {
	protected ApplicationContext applicationContext;
	protected String getWidth(TagNode node){
		return getStyle(node,"width");
	}
	protected String getHeight(TagNode node){
		return getStyle(node,"height");
	}
	private String getStyle(TagNode node,String styleName){
		String styles=node.getAttribute("style");
		if(StringUtils.isEmpty(styles))return null;
		String[] style=styles.split(";");
		for(int i=0;i<style.length;i++){
			String[] item=style[i].split(":");
			if(item[0].equals(styleName)){
				return item[1];
			}
		}
		return null;
	}
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		this.applicationContext=applicationContext;
	}
}
